﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="LocalizedRangeAttribute.shared.cs" company="Spenta Consulting">
//   (c) Copyright 2011
// </copyright>
// <summary>
//   Extends the RangeAttribute to provide a custom message
// </summary>
// --------------------------------------------------------------------------------------------------------------------

namespace Spenta.StreetCare.Core.Shared.Attributes
{
    using System;
    using System.ComponentModel.DataAnnotations;

    /// <summary>
    /// Extends the RangeAttribute to provide a custom message
    /// </summary>
    public class LocalizedRangeAttribute : RangeAttribute
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="LocalizedRangeAttribute"/> class.
        /// </summary>
        /// <param name="minimum">The minimum.</param>
        /// <param name="maximum">The maximum.</param>
        public LocalizedRangeAttribute(int minimum, int maximum)
            : base(minimum, maximum)
        {
            this.InitializeErrorMessageResource();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LocalizedRangeAttribute"/> class.
        /// </summary>
        /// <param name="minimum">The minimum.</param>
        /// <param name="maximum">The maximum.</param>
        public LocalizedRangeAttribute(double minimum, double maximum)
            : base(minimum, maximum)
        {
            this.InitializeErrorMessageResource();
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="LocalizedRangeAttribute"/> class.
        /// </summary>
        /// <param name="type">Specifies the type of the object to test.</param>
        /// <param name="minimum">Specifies the minimum value allowed for the data field value.</param>
        /// <param name="maximum">Specifies the maximum value allowed for the data field value.</param>
        /// <exception cref="T:System.ArgumentNullException">
        /// <paramref name="type"/> is null.</exception>
        public LocalizedRangeAttribute(Type type, string minimum, string maximum)
            : base(type, minimum, maximum)
        {
            this.InitializeErrorMessageResource();
        }

        /// <summary>
        /// Initializes the error message resource.
        /// </summary>
        private void InitializeErrorMessageResource()
        {
            ErrorMessageResourceName = "Range_ValidationError";
            ErrorMessageResourceType = typeof(Silverlight.Resources.Spenta_StreetCare_Core);
        }
    }
}